<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:s="http://jboss.com/products/seam/taglib"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:a="https://ajax4jsf.dev.java.net/ajax"
                xmlns:rich="http://richfaces.ajax4jsf.org/rich"
                template="layout/template.xhtml">
                       
<ui:define name="body">
    
    <h:messages globalOnly="true" styleClass="message" id="globalMessages"/>

    <h:form id="user" styleClass="edit">
    
        <rich:panel>
            <f:facet name="header">Edit User</f:facet>

            <s:decorate id="usernameDecoration" template="layout/edit.xhtml">
                <ui:define name="label">username</ui:define>
                <h:inputText id="username"
                          value="#{userHome.instance.username}">
                    <a:support event="onblur" reRender="usernameDecoration" bypassUpdates="true"/>
                </h:inputText>
            </s:decorate>

            <s:decorate id="passwordDecoration" template="layout/edit.xhtml">
                <ui:define name="label">password</ui:define>
                <h:inputText id="password"
                          value="#{userHome.instance.password}">
                    <a:support event="onblur" reRender="passwordDecoration" bypassUpdates="true"/>
                </h:inputText>
            </s:decorate>

            <s:decorate id="nameDecoration" template="layout/edit.xhtml">
                <ui:define name="label">name</ui:define>
                <h:inputText id="name"
                          value="#{userHome.instance.name}">
                    <a:support event="onblur" reRender="nameDecoration" bypassUpdates="true"/>
                </h:inputText>
            </s:decorate>
        
            <div style="clear:both">
                <span class="required">*</span> 
                required fields
            </div>
            
        </rich:panel>
                
        <div class="actionButtons">

            <h:commandButton id="save" 
                          value="Save" 
                         action="#{userHome.persist}"
                       disabled="#{!userHome.wired}"
                       rendered="#{!userHome.managed}"/>  
                          			  
            <h:commandButton id="update" 
                          value="Save" 
                         action="#{userHome.update}"
                       rendered="#{userHome.managed}"/>
                        			  
            <h:commandButton id="delete" 
                          value="Delete" 
                         action="#{userHome.remove}"
                       rendered="#{userHome.managed}"/>
                    
            <s:button id="done" 
                   value="Done"
             propagation="end"
                    view="/User.xhtml"
                rendered="#{userHome.managed}"/>
                
            <s:button id="cancel" 
                   value="Cancel"
             propagation="end"
                    view="/#{empty userFrom ? 'UserList' : userFrom}.xhtml"
                rendered="#{!userHome.managed}"/>

        </div>
    </h:form>

    <rich:tabPanel switchType="ajax">

        <rich:tab label="contents">
            <div class="association" id="contentsChildren">

                <h:outputText value="No contents"
                           rendered="#{empty userHome.contents}"/>

                <rich:dataTable value="#{userHome.contents}"
                               var="content"
                          rendered="#{not empty userHome.contents}"
                        rowClasses="rvgRowOne,rvgRowTwo"
                                id="contentsTable">
                    <h:column>
                        <f:facet name="header">id</f:facet>
                        <h:outputText value="#{content.id}"/>
                    </h:column>
                    <h:column>
                        <f:facet name="header">title</f:facet>
                        <h:outputText value="#{content.title}"/>
                    </h:column>
                    <h:column>
                        <f:facet name="header">creationDate</f:facet>
                        <h:outputText value="#{content.creationDate}"/>
                    </h:column>
                    <h:column>
                        <f:facet name="header">action</f:facet>
                        <s:link view="/Content.xhtml"
                                  id="selectcontent"
                               value="Select"
                         propagation="none">
                            <f:param name="contentId"
                                    value="#{content.id}"/>
                            <f:param name="contentFrom" value="User"/>
                        </s:link>
                    </h:column>
                </rich:dataTable>

            </div>
        </rich:tab>
    </rich:tabPanel>

</ui:define>

</ui:composition>
